package cn.btks.resultintegration.rule.controller;

import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import cn.btks.resultintegration.rule.pojo.*;
import cn.btks.resultintegration.rule.service.TwoHighFirstCategoryService;
import cn.btks.resultintegration.rule.service.TwoHighForthCategoryService;
import cn.btks.resultintegration.rule.service.TwoHighSecondCategoryService;
import cn.btks.resultintegration.rule.service.TwoHighThirdCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lijun
 * @Date 2021/10/15 10:22
 */
@RestController
@RequestMapping("api/v1.0/resultIntegration/rule")
@Api(tags = "规则模块")
@Validated
public class TwoHighIndustrialController {

    @Autowired
    TwoHighFirstCategoryService twoHighFirstCategoryService;

    @Autowired
    TwoHighSecondCategoryService twoHighSecondCategoryService;

    @Autowired
    TwoHighThirdCategoryService twoHighThirdCategoryService;

    @Autowired
    TwoHighForthCategoryService twoHighForthCategoryService;

    @GetMapping("/twoHigh/findAll")
    @ApiOperation("查询所有两高行业-门类")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAll() {
        List<TwoHighFirstCategory> list = twoHighFirstCategoryService.findAll();
        return list != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), list) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/twoHigh/findByFirstParentId/{id}")
    @ApiOperation("根据门类ID查询所有两高行业-大类")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "门类ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findByFirstParentId(@PathVariable("id") Long id) {
        List<TwoHighSecondCategory> list = twoHighSecondCategoryService.findAllByParentId(id);
        return list != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), list) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/twoHigh/findBySecondParentId/{id}")
    @ApiOperation("根据大类ID查询所有两高行业-中类")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "大类ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findBySecondParentId(@PathVariable("id") Long id) {
        List<TwoHighThirdCategory> list = twoHighThirdCategoryService.findAllByParentId(id);
        return list != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), list) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/twoHigh/findByThirdParentId/{id}")
    @ApiOperation("根据中类ID查询所有两高行业-小类")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "中类ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findByThirdParentId(@PathVariable("id") Long id) {
        List<TwoHighForthCategory> list = twoHighForthCategoryService.findAllByParentId(id);
        return list != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), list) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }
}
